﻿using System;
using System.Web;

namespace NWebMock
{
    public class TraceContextWrapper : ITraceContext
    {
        #region Constructors

        public TraceContextWrapper(TraceContext trace)
        {
            if (trace == null)
            {
                throw new ArgumentNullException("trace");
            }

            this.innerTrace = trace;
            trace.TraceFinished += new TraceContextEventHandler(OnTraceFinished);
        }

        #endregion

        #region Fields

        private TraceContext innerTrace = null;

        #endregion

        #region Properties

        public bool IsEnabled { get { return this.innerTrace.IsEnabled; } set { this.innerTrace.IsEnabled = value; } }

        public TraceMode TraceMode { get { return this.innerTrace.TraceMode; } set { this.innerTrace.TraceMode = value; } }

        #endregion

        #region Methods

        protected void OnTraceFinished(object sender, TraceContextEventArgs e)
        {
            if (this.TraceFinished != null)
            {
                this.TraceFinished(this, e);
            }
        }

        public void Warn(string message)
        {
            this.innerTrace.Warn(message);
        }

        public void Warn(string category, string message)
        {
            this.innerTrace.Warn(category, message);
        }

        public void Warn(string category, string message, Exception errorInfo)
        {
            this.innerTrace.Warn(category, message, errorInfo);
        }

        public void Write(string message)
        {
            this.innerTrace.Write(message);
        }

        public void Write(string category, string message)
        {
            this.innerTrace.Write(category, message);
        }

        public void Write(string category, string message, Exception errorInfo)
        {
            this.innerTrace.Write(category, message, errorInfo);
        }

        #endregion

        #region Events

        public event TraceContextEventHandler TraceFinished;

        #endregion
    }
}
